<?php
$T->loadTpl("./html/".$template."/".$qname.".html");
$T->SetTpl('cssjs','html/cssjs.inc'); 
$T->SetTpl('jsmodel','html/jsmodel.inc');     
  
$uid=$_SESSION['uid'];
$id=isset($_GET["id"])?$_GET["id"]:"";
$T->readDB("select type,name,start_time,end_time,dept_id,accepter,charge_uid,remark from sys_plan where id={$id}");
if($id!=''){
    $plan=$T->db->query("select attachment,accepter,dept_id,charge_uid,content from sys_plan where id={$id}")->fetch(PDO::FETCH_ASSOC);
    if($plan){           
        //附件
        $attachment=$plan['attachment'];
        if($attachment!=''){
            $attachment=explode(",", $attachment);
            foreach($attachment as $k=>$v){
                $attachment[$k]="'".$v."'";
            }
            $attachment=implode(",", $attachment);
            $attachment_info=$T->db->query("select id,name,save_path from sys_plan_attachment where id in({$attachment}) order by `timestamp`")->fetchAll(PDO::FETCH_ASSOC);
            $attachment_html="";
            foreach($attachment_info as $k=>$v){
                $attachment_html.='<span class="attachment_span"><a class="attachment_one" href="'.$v['save_path'].'">'.$v['name'].'</a><a class="attachment_one_del" data-id="'.$v['id'].'">[删除]</a></span>';
            }
            $T->Set("attachment_html",$attachment_html);
            $T->Set("attachment_arr",json_encode($attachment_info));
        }
        //发布人员
        $accepter = $plan['accepter'];
        if($accepter!=''){
            $acceptearr=explode(",", $accepter);
            $acceptnamearr=array();
            foreach($acceptearr as $k=>$v){
                $acceptnamearr[]=$T->db->query("select truename from sys_member where id='".$v."'")->fetchColumn(0);
            }
            $acceptname = implode(',', $acceptnamearr);
             $T->Set("acceptname",$acceptname);
        }
        //发布部门
        $dept_id = $plan['dept_id'];
        if($dept_id!=''){
            $dept_idarr=explode(",", $dept_id);
            $deptnamearr=array();
            foreach($dept_idarr as $k=>$v){
                $deptnamearr[]=$T->db->query("select deptname from sys_department where id='".$v."'")->fetchColumn(0);
            }
            $deptname = implode(',', $deptnamearr);
             $T->Set("deptname",$deptname);
        }
        //负责人
        $charge_uid = $plan['charge_uid'];
        if($charge_uid!=''){
            $charge_uidarr=explode(",", $charge_uid);
            $chargenamearr=array();
            foreach($charge_uidarr as $k=>$v){
                $chargenamearr[]=$T->db->query("select truename from sys_member where id='".$v."'")->fetchColumn(0);
            }
            $chargename = implode(',', $chargenamearr);
             $T->Set("chargename",$chargename);
        }
        $T->Set("content",htmlspecialchars_decode($plan['content'],ENT_QUOTES));
    }
}
$T->Set("id",$id);
$T->Set("uid",$uid);
$T->SetBlock("types","select id,name from sys_plan_type order by odx");     

$T->Set("template",$template);
$T->clearNaN();       
$T->clearNoN();
$T->display(); 